﻿using SH.Common.CommonReturn;
using SH.Common.DataDictionary;
using SqlSugar;
using System.Linq.Expressions;
using System.Security.AccessControl;

namespace SH.Customer.Infrastructure.IRepository
{
    public interface IBaseRepository<T> where T : class, new()
    {
        ISugarQueryable<T> All { get; }

        #region 同步
        //增
        int Insert(T t);

        //批量增
        int BatchInsert(List<T> list);

        //删
        int Delete(T t);

        //批量删除
        int BatchDelete(List<T> list);

        //改
        int Upd(T t);

        //批量修改
        int BatchUpd(List<T> list);

        //查
        List<T> GetList();

        //分页
        ApiPaging<List<T>> PageQuery(ISugarQueryable<T> list, Expression<Func<T, bool>>? where, string? orderBy, int pageSize, int pageIndex);

        //Expression<>获取实体
        T GetModelByCondition(Expression<Func<T, bool>> where);

        //Expression<>获取集合
        List<T> GetListByCondition(Expression<Func<T, bool>> where);

        //多租户开启事务
        void MultitenantBeginTran();

        //多租户提交事务
        void MultitenantCommit();

        //多租户事务回滚
        void MultitenantRollBack();
        #endregion

        #region 异步
        //增
        Task<int> InsertAsync(T t);

        //批量增
        Task<int> BatchInsertAsync(List<T> list);

        //查
        Task<List<T>> GetListAsync();

        //分页
        Task<ApiPaging<List<T>>> PageQueryAsync(ISugarQueryable<T> list, Expression<Func<T, bool>>? where, string? orderBy, int pageSize, int pageIndex);

        //Expression<>获取实体
        Task<T> GetModelByConditionAsync(Expression<Func<T, bool>> where);

        //Expression<>获取集合
        Task<List<T>> GetListByConditionAsync(Expression<Func<T, bool>> where);

        //多租户开启事务
        void MultitenantBeginTranAsync();

        //多租户提交事务
        void MultitenantCommitAsync();

        //多租户事务回滚
        void MultitenantRollBackAsync();
        #endregion

        ISugarQueryable<Dic> GetDics();
    }
}
